/* 
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package org.shanekjohnson.cmis.client.atompub.service
{
	import org.shanekjohnson.cmis.client.atompub.model.Property;
	import org.shanekjohnson.cmis.client.atompub.model.Repository;
	
	import flexunit.framework.Assert;
	
	public class RepositoryInfoServiceTest
	{
		private namespace app = "http://www.w3.org/2007/app";
		private namespace atom = "http://www.w3.org/2005/Atom";
		private namespace cmis = "http://docs.oasis-open.org/ns/cmis/core/200901";
		
		use namespace app;
        use namespace atom;
        use namespace cmis;
        
		private static const repoInfo:XML = 
			<app:service xmlns:cmis="http://docs.oasis-open.org/ns/cmis/core/200908/" xmlns:cmism="http://docs.oasis-open.org/ns/cmis/messaging/200908/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:app="http://www.w3.org/2007/app" xmlns:cmisra="http://docs.oasis-open.org/ns/cmis/restatom/200908/">
			    <app:workspace>
			        <atom:title type="text">CMIS Repository</atom:title>
			        <app:collection href="http://cmisexample.oasis-open.org/rep1//checkedout">
			            <atom:title type="text">Checkedout collection</atom:title>
			            <app:accept>application/atom+xml;type=entry</app:accept>
			            <cmisra:collectionType>checkedout</cmisra:collectionType>
			        </app:collection>
			        <app:collection href="http://cmisexample.oasis-open.org/rep1//query">
			            <atom:title type="text">Query collection</atom:title>
			            <app:accept>application/cmisquery+xml</app:accept>
			            <cmisra:collectionType>query</cmisra:collectionType>
			        </app:collection>
			        <app:collection href="http://cmisexample.oasis-open.org/rep1//rootc">
			            <atom:title type="text">Root children collection</atom:title>
			            <cmisra:collectionType>root</cmisra:collectionType>
			        </app:collection>
			        <app:collection href="http://cmisexample.oasis-open.org/rep1//typec">
			            <atom:title type="text">Types children collection</atom:title>
			            <cmisra:collectionType>types</cmisra:collectionType>
			        </app:collection>
			        <app:collection href="http://cmisexample.oasis-open.org/rep1//unfiled">
			            <atom:title type="text">Unfiled collection</atom:title>
			            <app:accept>application/atom+xml;type=entry</app:accept>
			            <cmisra:collectionType>unfiled</cmisra:collectionType>
			        </app:collection>
			        <app:collection href="http://cmisexample.oasis-open.org/rep1//changes">
			            <atom:title type="text">changes collection</atom:title>
			            <cmisra:collectionType>changes</cmisra:collectionType>
			        </app:collection>
			        <atom:link title="Types Descendants feed" type="application/atom+xml;type=feed" rel="http://docs.oasis-open.org/ns/cmis/link/200908/typedescendants" href="http://cmisexample.oasis-open.org/rep1//typesdescendants"/>
			        <atom:link title="Folder Tree feed for root folder" type="application/atom+xml;type=feed" rel="http://docs.oasis-open.org/ns/cmis/link/200908/foldertree" href="http://cmisexample.oasis-open.org/rep1//foldertree"/>
			        <cmisra:repositoryInfo>
			            <cmis:repositoryId>repid1</cmis:repositoryId>
			            <cmis:repositoryName>Repository1</cmis:repositoryName>
			            <cmis:repositoryDescription>CMIS Repository Description</cmis:repositoryDescription>
			            <cmis:vendorName>CMIS Vendor 1</cmis:vendorName>
			            <cmis:productName>CMIS Prototype for VendorX</cmis:productName>
			            <cmis:productVersion>1.0</cmis:productVersion>
			            <cmis:rootFolderId>rootfolder</cmis:rootFolderId>
			            <cmis:latestChangeLogToken>token-Thu Dec 24 09:01:46 PST 2009</cmis:latestChangeLogToken>
			            <cmis:capabilities>
			                <cmis:capabilityACL>manage</cmis:capabilityACL>
			                <cmis:capabilityAllVersionsSearchable>true</cmis:capabilityAllVersionsSearchable>
			                <cmis:capabilityChanges>all</cmis:capabilityChanges>
			                <cmis:capabilityContentStreamUpdatability>anytime</cmis:capabilityContentStreamUpdatability>
			                <cmis:capabilityGetDescendants>true</cmis:capabilityGetDescendants>
			                <cmis:capabilityGetFolderTree>false</cmis:capabilityGetFolderTree>
			                <cmis:capabilityMultifiling>true</cmis:capabilityMultifiling>
			                <cmis:capabilityPWCSearchable>true</cmis:capabilityPWCSearchable>
			                <cmis:capabilityPWCUpdatable>true</cmis:capabilityPWCUpdatable>
			                <cmis:capabilityQuery>bothcombined</cmis:capabilityQuery>
			                <cmis:capabilityRenditions>read</cmis:capabilityRenditions>
			                <cmis:capabilityUnfiling>true</cmis:capabilityUnfiling>
			                <cmis:capabilityVersionSpecificFiling>true</cmis:capabilityVersionSpecificFiling>
			                <cmis:capabilityJoin>innerandouter</cmis:capabilityJoin>
			            </cmis:capabilities>
			            <cmis:cmisVersionSupported>1.0</cmis:cmisVersionSupported>
			            <cmis:changesIncomplete>true</cmis:changesIncomplete>
			            <cmis:changesOnType>cmis:document</cmis:changesOnType>
			            <cmis:changesOnType>cmis:folder</cmis:changesOnType>
			        </cmisra:repositoryInfo>
			        <!--
			        <cmisra:uritemplate>
			            <cmisra:template>http://cmisexample.oasis-open.org/rep1/objectbyid/{id}?filter={filter}&amp;includeAllowableActions={includeAllowableActions}&amp;includePolicyIds={includePolicyIds}&amp;includeRelationships={includeRelationships}&amp;includeACL={includeACL}</cmisra:template>
			            <cmisra:type>objectbyid</cmisra:type>
			            <cmisra:mediatype>application/atom+xml;type=entry</cmisra:mediatype>
			        </cmisra:uritemplate>
			        <cmisra:uritemplate>
			            <cmisra:template>http://cmisexample.oasis-open.org/rep1/objectbypath?p={path}&amp;filter={filter}&amp;includeAllowableActions={includeAllowableActions}&amp;includePolicyIds={includePolicyIds}&amp;includeRelationships={includeRelationships}&amp;includeACL={includeACL}</cmisra:template>
			            <cmisra:type>objectbypath</cmisra:type>
			            <cmisra:mediatype>application/atom+xml;type=entry</cmisra:mediatype>
			        </cmisra:uritemplate>
			        <cmisra:uritemplate>
			            <cmisra:template>http://cmisexample.oasis-open.org/rep1/query?q={path}&amp;searchAllVersions={searchAllVersions}&amp;maxItems={maxItems}&amp;skipCount={skipCount}&amp;includeAllowableActions={includeAllowableActions}=&amp;includeRelationships={includeRelationships}</cmisra:template>
			            <cmisra:type>query</cmisra:type>
			            <cmisra:mediatype>application/atom+xml;type=entry</cmisra:mediatype>
			        </cmisra:uritemplate>
			        -->
			    </app:workspace>
			</app:service>;
			
		private var repository:Repository;
			
		public function RepositoryInfoServiceTest()
		{
			var repoInfoService:RepositoryInfoService = new RepositoryInfoService("");
			
			repository = repoInfoService.getRepositoryInfo(repoInfo);
		}

        [Test]
		public function testChildrenURL():void 
		{
			Assert.assertEquals("http://cmisexample.oasis-open.org/rep1//rootc", repository.childrenURL);
   		}

        [Test]
		public function testQueryURL():void 
		{
   			Assert.assertEquals("http://cmisexample.oasis-open.org/rep1//query", repository.queryURL);
   		}

        [Test]
		public function testTypesURL():void 
		{
   			Assert.assertEquals("http://cmisexample.oasis-open.org/rep1//typec", repository.typesURL);
   		}

        [Test]
   		public function testPropertyId():void 
   		{
   			var prop:Property = repository.properties.getItemAt(0) as Property;
   			
   			Assert.assertEquals("repositoryId", prop.name);
   			Assert.assertEquals("repid1", prop.value);
   		}

        [Test]
   		public function testCapabilityACL():void 
   		{
   			var prop:Property = repository.capabilities.getItemAt(0) as Property;
   			
   			Assert.assertEquals("capabilityACL", prop.name);
   			Assert.assertEquals("manage", prop.value);
   		}

	}
	
}